package com.jiangman.weather;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.jiangman.weather.bean.TabEntity;
import com.jiangman.weather.ui.fragment.MeFragment;
import com.jiangman.weather.ui.fragment.NewsFragment;
import com.jiangman.weather.ui.fragment.WeatherFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import util.HttpRequestUtils;
import util.SPUtils;

public class MainActivity extends AppCompatActivity {
    @BindView(R.id.tzain_fl_ui)
    FrameLayout tzainFlUi;
    @BindView(R.id.main_tab_bottom)
    CommonTabLayout mainTabBottom;
    private String[] mTitles = {"", "", ""};
    private int[] mIconUnselectIds = {
            R.drawable.vector_drawable_yun_grey, R.mipmap.tiezi_before,
            R.drawable.vector_drawable_me_grey};
    private int[] mIconSelectIds = {
            R.drawable.vector_drawable_yun_blue, R.mipmap.tiezi_after,
            R.drawable.vector_drawable_me_blue};

    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ButterKnife.bind(this);
        initTab();
        initData();
    }

    private void initData() {
//        SPUtils.setSharedStringData(getActivity(),"userName",data.username);
//        SPUtils.setSharedStringData(getActivity(),"userId",String.valueOf(data.id));
        String userName = SPUtils.getSharedStringData(this, "userName");
        String userPwd = SPUtils.getSharedStringData(this, "userPwd");

        if(!TextUtils.isEmpty(userName)&&!TextUtils.isEmpty(userPwd)){
            HttpRequestUtils httpRequestUtils = new HttpRequestUtils();
            httpRequestUtils.setAutoUserLogin(userName,userPwd);
        }
    }


    private void initTab() {

        mFragments.add(new WeatherFragment());
        mFragments.add(new NewsFragment());
        mFragments.add(new MeFragment());

        for (int i = 0; i < mTitles.length; i++) {
            mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
        }

        mainTabBottom.setTabData(mTabEntities, this, R.id.tzain_fl_ui, mFragments);

    }
}
